import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_he/page/adopt/model/xin_he_adopt_tree_record_model_entity.dart';
import 'package:xin_he/utils/xin_he_UI_constancs.dart';

import '../../../utils/xh_styles.dart';
import '../../../utils/xin_he_image.dart';
import '../../shopping_car/xin_he_instant_pay/xin_he_instant_pay_view.dart';
import 'xin_he_adopt_records_logic.dart';

class XinHeAdoptRecordsPage extends StatelessWidget {
  XinHeAdoptRecordsPage({Key? key}) : super(key: key);

  final logic = Get.put(XinHeAdoptRecordsLogic());
  final state = Get.find<XinHeAdoptRecordsLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
      appBar: AppBar(
        leading: IconButton(
            onPressed: (){
              Get.back();
            },
            icon: Container(
              padding: EdgeInsets.only(left: 7),
              alignment: Alignment.centerLeft,
              child: const XinHeAssetImage(
                'assets/images/home/app_back_3.png',
                width: 9.5,
                height: 17,
                fit: BoxFit.cover,),
            )
        ),
        backgroundColor: Colors.white,
        shadowColor: Colors.transparent,
        title: Text('认养记录',style: TextStyle(color:XinHeColor('##222222'),fontSize: 17,fontWeight: FontWeight.w600)),
        centerTitle: true,
      ),
      body: logic.recordsList.isNotEmpty? ListView.builder(
          padding: const EdgeInsets.only(top: 10),
          itemCount: logic.recordsList.length,
          itemBuilder: (ctx,index){
            XinHeAdoptTreeRecordModelEntity model = logic.recordsList[index];
            return _itemView( model);
          }):const Center(child: Text('暂无记录'),),

    ));
  }

  Widget _itemView(XinHeAdoptTreeRecordModelEntity model){
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 15),
      height: 123,
      width: Get.width,
      color: Colors.white,
      child: Column(
        children: [
        SizedBox(height: 20,),
        Row(children: [
          XinHeNetImage(url: model.treeIconPath??'',width: 80,height: 80,),
          SizedBox(width: 5,),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
              Row(children: [
                Text(model.treeName??'',style: TextStyle(color: XinHeColor('#222222'),fontSize: 14,fontWeight: FontWeight.w500),),
                Spacer(),
                Text('x${model.amount??0}',style: TextStyle(color: XinHeColor('#555555'),fontSize: 13,fontWeight: FontWeight.w500),),

              ],),
              SizedBox(height: 8,),

             Row(children: [
               Column(children: [
                 Text(model.startTime != null ? '认养时间：${model.startTime??''}':'',style: TextStyle(color: XinHeColor('#666666'),fontSize: 12,fontWeight: FontWeight.w500),),
                 Text(model.endTime != null ? '到期时间：${model.endTime??''}' : '',style: TextStyle(color: XinHeColor('#666666'),fontSize: 12,fontWeight: FontWeight.w500),),
               ],),

               Spacer(),
            model.payChannel != 'OFFLINE' && model.status == 'UN_PAY' ?  GestureDetector(
                 onTap: (){
                   Get.bottomSheet(XinHeInstantPayPage(
                     zoneType: 5,
                     totalPrice:model.price!.toDouble(),
                     count: model.amount!,
                     order: {'orderId':model.id},
                     scene: PayScene.fromAdoptRecordsList,),
                     persistent: false,isScrollControlled: true,);
                 },
                 child: Container(
                   height: 30,
                   width: 75,
                   alignment: Alignment.center,
                   decoration: BoxDecoration(
                     gradient:  LinearGradient(colors: [ XinHeColor('##F89A30'), XinHeColor('#E84128')]),
                     borderRadius: BorderRadius.circular(15),
                   ),
                   child:  const Text('待支付',style: TextStyle(color: Colors.white,fontSize: 14),strutStyle: StrutStyle(forceStrutHeight: true),),
                 ),
               ):Container(),

             ],)



            ],),
          )
        ],),
          Spacer(),
          Container(height: 0.5,width: Get.width-30,color: XinHeStyle.lineColor,)
      ],),
    );
  }
}
